home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15526 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  50 lines

  1. Path: news.uni-c.dk!news
  2. From: maspsr@dou.ou.dk (peter S°rensen)
  3. Newsgroups: comp.infosystems.www.servers.unix,comp.lang.c
  4. Subject: Re: Opening a binary file.... (dealing with content-type & WWW)
  5. Date: 19 Apr 1996 10:58:21 GMT
  6. Organization: DOU
  7. Message-ID: <4l7rkd$9a7@news.uni-c.dk>
  8. References: <317351DE.E7E@draper.com>
  9. NNTP-Posting-Host: peter.dou.dk
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.93.11
  12.  
  13. In article <317351DE.E7E@draper.com>, bshalton@draper.com says...
  14. >
  15. >Hello, 
  16. >
  17. >I am trying to establish content-types (mime) based upon the header 
  18. >of the file, rather than relying on the file extension.  I have 
  19. >instances where file extensions overlap...ex. .doc (microsoft word), 
  20. >.doc (ascii text document).
  21. >
  22. >To be able to set the content-type correctly to launch the 
  23. >appropriate viewer, I am modifying the "file" command to be able to 
  24. >look up by magic types.  I have coded the magic type  
  25. >application/msword in the magic file.  The modified file program 
  26. >would then open the desired file, and stream it out to the user.
  27. >
  28. >Originally I was doing a fork/exec and basically cat'ting the file.  
  29. >This works under Solaris, but for some reason, it doesn't work on 
  30. >SunOS.  Plus, I have seen hung processes.  
  31. >
  32. >I have decided to take out the fork/exec and replace it with a 
  33. >simple open file, read contents, send to browser routine.
  34. >
  35. >This is my first cut...
  36. >
  37. >
  38. >
  39. >                fd2=open(entries[0].val,O_RDONLY);
  40. >                for(;;)
  41. >                        {
  42. >                if(     read(fd2, tbuf, 1) <=0 ) exit(1);
  43. >                        printf("%s", tbuf);
  44. >                        }
  45.  
  46. Use the O_BINARY flag to tell the open that this file is binary.
  47.  
  48. Peter Sorensen/University of Odense,dk/e-mail:maspsr@dou.ou.dk
  49.  
  50.